import Vue from 'Vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const state = {
  count: 2
}
const mutations = {
  RESET (state) {
    state.count = 0
    console.log('do RESET mutations',state.count)
  },
  ADD (state) {
    state.count++
    console.log('do ADD mutations',state.count)
    
  },
  REDUCE (state) {
    state.count--
    console.log('do REDUCE mutations',state.count)
  }
}
const actions = {
  reset (context) {
    console.log('do reset actions')
    context.commit('RESET')
  },
  add (context) {
    setTimeout(()=>{
      console.log('do add actions')
      context.commit('ADD')
    },2000);
    
  },
  reduce (context) {
    console.log('do reduce actions')
    context.commit('REDUCE')
  }
}

export default new Vuex.Store({
  state,
  mutations,
  actions
})
